package main

import (
	"gorm.io/gorm"

	"torler.com/qingyue/apps/importer/config"
	"torler.com/qingyue/apps/importer/job"
	"torler.com/qingyue/common/model"
	"torler.com/qingyue/pkg/logger"
	"torler.com/qingyue/pkg/storage"
)

func main() {
	if err := config.LoadConfig(); err != nil {
		panic(err)
	}
	conf := config.GetConfig()
	rule, err := config.LoadRule()
	if err != nil {

		panic(err)
	}

	logger.Init(conf.Log)
	db := storage.NewDatabase(conf.DB)
	db.Connect()
	autoMigrate(db.DB)

	job.NewBookImporter(db.DB, rule, logger.Default()).Run()

}
func autoMigrate(db *gorm.DB) {
	db.AutoMigrate(&model.RawBook{})

}
